<?php

class Sitemap_IndexController extends Zend_Controller_Action
{

    public function init()
    {
        $this->view->headTitle()->set(Zend_Registry::get('locale')->_('Sitemap'));
        
        $activeResource=Sitemap_Model_Sitemap::RESOURCE_NAME;
        
        // seting active resource
        Zend_Registry::set('resource',$activeResource);
    }
    
    /**
     * HTML Sitemap action
     */
    public function indexAction()
    {
        if (!Zend_Registry::get('user')->canView())
        {
            return $this->_response->setRedirect(Zend_Registry::get('view')->fixUrl());
        }
        
        $key=(int) $this->_getParam('key');

        Zend_Registry::get('layout')->setLayout('duty');
        
        list($nodes,$paginator)=Sitemap_Model_Sitemap::fetch($key);
        
        $this->view->nodes=$nodes;
        $this->view->paginator=$paginator;
    }

    /**
     * XML Sitemap action
     */
    public function xmlAction()
    {
        if (!Zend_Registry::get('user')->canView())
        {
            return $this->_response->setRedirect(Zend_Registry::get('view')->fixUrl());
        }
        
        Zend_Registry::get('layout')->setLayout('blank');
        
        header('Content-type: application/xml');

        list($nodes,$paginator)=Sitemap_Model_Sitemap::fetch();
        
        $this->view->nodes=$nodes;
    }
}

